#! /bin/sh
# Copyright (c) 1995-2001 SuSE GmbH Nuernberg, Germany
#                    2002 SuSE Linux AG, Nuernberg, Germany
#                    2005 SUSE LINUX Products GmbH, Nuernberg, Germany
#
# Author: Matthias Eckermann
#         Wolfgang Rosenauer
#
#
### BEGIN INIT INFO
# Provides:       pcscd
# Required-Start:  $remote_fs $syslog
# X-UnitedLinux-Should-Start: setserial hotplug kbd
# Required-Stop:   $remote_fs $syslog
# Default-Start:   2 3 5
# Default-Stop:    0 1 6 
# Description:     PCSC daemon handling smart card readers
### END INIT INFO


pcscd_BIN=/usr/local/pcsc-1.4.102/sbin/pcscd
test -x $pcscd_BIN || exit 5

. /etc/rc.status
rc_reset

case "$1" in
    start)
        echo -n "Starting PC/SC smart card daemon "
	mount -n -t usbfs usbfs /proc/bus/usb >/dev/null 2>&1
	rm -f /var/run/pcscd.pub
	startproc $pcscd_BIN
        rc_status -v
	;;
    stop)
        echo -n "Stopping PC/SC smart card daemon "
        killproc -TERM $pcscd_BIN
	rc_status -v
        ;;
    try-restart)
        $0 status >/dev/null &&  $0 restart
        rc_status
        ;;
    restart)
        $0 stop
        $0 start
        rc_status
        ;;
    force-reload)
        $0 stop  &&  $0 start
        rc_status
        ;;
    reload)
        echo -n "Reload PC/SC smart card daemon "
        rc_failed 3
        rc_status -v
        ;;
    status)
        echo -n "Checking for PC/SC smart card daemon  "
	checkproc $pcscd_BIN 
	rc_status -v
	;;
    *)
        echo "Usage: $0 {start|stop|try-restart|restart|force-reload|reload|status}"
        exit 1
        ;;
esac
rc_exit
